/**
 * @file       Panel_test.cpp
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 12, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#include "Panel.h"
#include "gtest/gtest.h"
#include "Context.h"
#include "errorcode.h"
#include "Label.h"
#include "Button.h"
#include "IEventListener.h"
#include "KeyboardListener.h"
namespace NS_LCD_AFW
{
class CPanel_test: public ::testing::Test
{
public:
	virtual void SetUp()
	{
	}
	virtual void TearDown()
	{
	}
};

TEST_F(CPanel_test,test_defualtConstruction)
{
	CPanel *pPanel = new CPanel();
	EXPECT_FALSE(pPanel->isHightlightable());
	EXPECT_TRUE(pPanel->isFocusable());
	OBJ_DESTORY(pPanel);
}
TEST_F(CPanel_test,test_getFocusObject)
{
	CPanel *pPanel = new CPanel();
	EXPECT_EQ(NULL,pPanel->getFocusObject());
	OBJ_DESTORY(pPanel);
}
TEST_F(CPanel_test,test_setFocusObject)
{
	CPanel *pPanel = new CPanel();
	EXPECT_EQ(NULL,pPanel->getFocusObject());
	CButton *pBtn1 = new CButton();
	EXPECT_EQ(NULL,pPanel->setFocusObject(pBtn1));
	CButton *pBtn2 = new CButton();
	EXPECT_EQ(pBtn1,pPanel->setFocusObject(pBtn2));
	EXPECT_EQ(pBtn2,pPanel->getFocusObject());
	OBJ_DESTORY(pPanel);
	OBJ_DESTORY(pBtn1);
	OBJ_DESTORY(pBtn2);
}
TEST_F(CPanel_test,test_onCreate)
{
	CPanel *pPanel = new CPanel();
	EXPECT_EQ(NULL,AfwGetContext()->getActivePanel());
	EXPECT_EQ(ERR_SUCCESS,pPanel->create("test",CRect(0,0,10,10),NULL,NULL));
	EXPECT_EQ(pPanel,AfwGetContext()->getActivePanel());
	EXPECT_EQ(pPanel,pPanel->getFocusObject());
	OBJ_DESTORY(pPanel);
	EXPECT_EQ(NULL,AfwGetContext()->getActivePanel());
}
TEST_F(CPanel_test,test_add)
{
	CPanel *pPanel = new CPanel();
	EXPECT_EQ(ERR_SUCCESS,pPanel->create("test",CRect(0,0,10,10),NULL,NULL));

	EXPECT_EQ(ERR_NULL_POINTER,pPanel->add(NULL));

	CButton *pBtn = new CButton();
	pBtn->create("testBtn",CRect(3,3,8,8));
	EXPECT_EQ(ERR_SUCCESS,pPanel->add(pBtn));
	CFrame *pChild = pPanel->getChild("testBtn");
	EXPECT_EQ(CRect(3,3,7,7),pChild->getRect());
	EXPECT_EQ(CPoint(3,3),pChild->getPosition());
	EXPECT_EQ(ERR_ELEMENT_EXISTS,pPanel->add(pBtn));

	CLabel *pLabel = new CLabel();
	pLabel->create("testLabel",CRect(3,11,8,8));
	EXPECT_EQ(ERR_SUCCESS,pPanel->add(pLabel));
	pChild = pPanel->getChild("testLabel");
	EXPECT_EQ(CRect(3,11,7,8),pChild->getRect());
	EXPECT_EQ(CPoint(3,1),pChild->getPosition());

	OBJ_DESTORY(pPanel);
}
TEST_F(CPanel_test,test_remove)
{
	CPanel *pPanel = new CPanel();
	EXPECT_EQ(ERR_SUCCESS, pPanel->create("test",CRect(0,0,10,10),NULL,NULL));
	CButton *pBtn = new CButton();
	pBtn->create("testBtn", CRect(3, 3, 8, 8));
	EXPECT_EQ(ERR_SUCCESS, pPanel->add(pBtn));
	EXPECT_EQ(pBtn,pPanel->getChild("testBtn"));
	EXPECT_EQ(ERR_SUCCESS,pPanel->remove(pBtn));
	EXPECT_EQ(ERR_ELEMENT_NOT_FOUND,pPanel->remove(pBtn));

	OBJ_DESTORY(pPanel);
	OBJ_DESTORY(pBtn);
}
TEST_F(CPanel_test,test_getChild)
{
	CPanel *pPanel = new CPanel();
	EXPECT_EQ(ERR_SUCCESS, pPanel->create("test",CRect(0,0,10,10),NULL,NULL));
	CButton *pBtn = new CButton();
	pBtn->create("testBtn", CRect(3, 3, 8, 8));
	EXPECT_EQ(ERR_SUCCESS, pPanel->add(pBtn));
	EXPECT_EQ(pBtn, pPanel->getChild("testBtn"));
	OBJ_DESTORY(pPanel);
}
TEST_F(CPanel_test,test_cleanChildObject)
{
}

TEST_F(CPanel_test,test_calculateViewPort)
{
}
TEST_F(CPanel_test,test_calculatePaging)
{
}
TEST_F(CPanel_test,test_sortFrameArray)
{
}
TEST_F(CPanel_test,test_onDraw)
{
}
TEST_F(CPanel_test,test_onSize)
{
}
TEST_F(CPanel_test,test_onRightKeyPress)
{
}
TEST_F(CPanel_test,test_onLeftKeyPress)
{
}
TEST_F(CPanel_test,test_onUpKeyPress)
{
}
TEST_F(CPanel_test,test_onDownKeyPress)
{
}
TEST_F(CPanel_test,test_onEnterKeyPress)
{
}
TEST_F(CPanel_test,test_notify)
{
	CPanel *pPanel = new CPanel();
	EXPECT_EQ(ERR_SUCCESS, pPanel->create("test",CRect(0,0,10,10),NULL,NULL));
	CButton *pBtn = new CButton();
	pBtn->create("testBtn", CRect(3, 3, 8, 8));
	EXPECT_EQ(ERR_SUCCESS, pPanel->add(pBtn));
	EXPECT_EQ(ERR_EVENT_UN_HANDLED,pPanel->notify(NULL));
	IEventListener *pListener = new CKeyboardListener(pPanel);
	pPanel->addEventListener(pListener);
	EXPECT_EQ(ERR_EVENT_UN_HANDLED,pPanel->notify(NULL));
	OBJ_DESTORY(pPanel);
}
TEST_F(CPanel_test,test_getChildFrameArray)
{
}
TEST_F(CPanel_test,test_setPagingStrategy)
{
}
} /* namespace NS_LCD_AFW */
